home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Texteditors / Origami / Sources / src / origami / keytab.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-27  |  7.2 KB  |  305 lines

  1. /*{{{}}}*/
  2. /*{{{  #includes*/
  3. #ifdef CONFIG_H
  4. #   include "config.h"
  5. #endif
  6.  
  7. #include <sys/types.h>
  8. #include <limits.h>
  9. #include <stdlib.h>
  10. #include <stdio.h>
  11. #include <string.h>
  12.  
  13. #define KEYTAB_C
  14. #define I_BUFFLOOP_C
  15. #define I_DISPLAY_C
  16. #define I_FIELDEDIT_C
  17. #define I_FINDS_C
  18. #define I_FOLDING_C
  19. #define I_GETMSG_C
  20. #define I_GETTK_C
  21. #define I_KEYBOARD_C
  22. #define I_LOOP_C
  23. #define I_MAIN_C
  24. #define I_PROMPT_C
  25. #define I_SCREEN_C
  26. #define I_SIGNALS_C
  27. #define I_VIRTUAL_C
  28.  
  29. #include "origami.h"
  30. #include <lib/ori_add_lib.h>
  31. #include <h/envvar_str.h>
  32. /*}}}  */
  33.  
  34. /*{{{  variables*/
  35. private KEY const *find_current;
  36. private KEY const *top_list;
  37. private int const *mark_list;
  38. public int const *bind_mark=0;
  39. public int curr_kbd=0;
  40. #ifdef MOUSY
  41.   public TOKEN *mouse_mapping=0;
  42. #endif
  43. public boolean quote_used=False;
  44. public int mouse_number=0;
  45. /*}}}  */
  46. /*{{{  key_infos key_info*/
  47. #include "permlist.h"
  48. /*}}}  */
  49.  
  50. /*{{{  kbd_change*/
  51. public void kbd_change(int const no)
  52. {
  53.   if
  54.    (    (unsigned int)no>=ktb_count
  55.      || !(find_current=top_list+(curr_kbd=no))
  56.    )
  57.      exit_origami(r_ocl_err,get_msg(F_INT_OCL,STR_KEYTABLE));
  58.   bind_mark= mark_list+no;
  59. }
  60. /*}}}  */
  61. /*{{{  set_key_top*/
  62. public void set_key_top (KEY const * const top,int const * const marks)
  63. {
  64.   ori_assert(top,"kbd missing");
  65.   find_current=top_list=top;
  66.   bind_mark=mark_list=marks;
  67.   kbd_change(curr_kbd);
  68. }
  69. /*}}}  */
  70. /*{{{  find_key*/
  71. public int find_key (int const key)
  72. {
  73.   KEY const *find;
  74.  
  75.   /*{{{  quoting???*/
  76.   if (find_current==(KEY*)0)
  77.    { find_current=top_list+curr_kbd;
  78.      quote_used=True;
  79.      return((key&(O_NOP-1)));
  80.    }
  81.   /*}}}  */
  82.   quote_used=False;
  83.   /*{{{  search in tree*/
  84.   for (find = key_level_ptr(find_current);find;)
  85.    { if (key_match(find,key))
  86.         break;
  87.      find=key_next_ptr(find);
  88.      while (key_far_next(find))
  89.         find=key_level_ptr(find);
  90.    }
  91.   /*}}}  */
  92.   switch (key_code(find))
  93.    { case 0:
  94.         if (key_level_ptr(find))
  95.          /*{{{  search continues*/
  96.          { find_current = find;
  97.            return (keytabcont);
  98.          }
  99.          /*}}}  */
  100.         else
  101.          /*{{{  no level below this, the search ends*/
  102.          { find_current=top_list+curr_kbd;
  103.            return(keytabend);
  104.          }
  105.          /*}}}  */
  106.      case K_QUOTE:
  107.         /*{{{  return continue, store quote*/
  108.         find_current=0;
  109.         return(keytabcont);
  110.         /*}}}  */
  111.      default:
  112.         /*{{{  return found TOKEN, maybe shifted*/
  113.         { find_current=top_list+curr_kbd;
  114.           return (find->code);
  115.         }
  116.         /*}}}  */
  117.    }
  118. }
  119. /*}}}  */
  120. /*{{{  valid_key*/
  121. public boolean valid_key(TOKEN const ch)
  122. {
  123.   if
  124.    (!(    (   ch==O_CREATE_FOLD
  125.            && (   (    ocl_var[var_mod_beh].v!=(fold_selection-1)
  126.                     && ocl_var[var_mod_beh].v!=(unmark_fold_selection-1)
  127.                   )
  128.                || (    bd.m.select_mode!=no_selection
  129.                     && bd.m.select_mode!=fold_selection
  130.                     && bd.m.select_mode!=unmark_fold_selection
  131.                   )
  132.               )
  133.           )
  134.        || (   ch>=O_NOP
  135.            && ch<K_QUOTE
  136.            && key_info[ch-O_NOP]&KTI_B
  137.           )
  138.      )
  139.    )
  140.      if (bd.m.read_only)
  141.       { msg_message(M_VIEW);
  142.         ocl_var[var_ocl_arg].v=ch;
  143.         if (view_macro)
  144.            call_number_macro(view_macro);
  145.         return False;
  146.       }
  147.      else
  148.       { if (bd.m.file_changed_status!=changed_file)
  149.          { bd.m.file_changed_status++;
  150.            title_op(CHGTITLE);
  151.          }
  152.       }
  153.   return True;
  154. }
  155. /*}}}  */
  156. /*{{{  valid_field_key check if token is a correct field_key*/
  157. public boolean valid_field_key(TOKEN const ch)
  158. {
  159.   return(ch<O_NOP || (ch<K_QUOTE && key_info[ch - O_NOP]&KTI_F));
  160. }
  161. /*}}}  */
  162. /*{{{  valid_screen_key*/
  163. public int valid_screen_key(TOKEN const ch)
  164. {
  165.   if (ch>=O_NOP && ch<K_QUOTE && !(key_info[ch-O_NOP]&KTI_S))
  166.      switch (bd.m.select_mode)
  167.       { default:                     return(0);
  168.  
  169.         case no_selection: break;/* =return(1) */
  170.  
  171.         case pseudo_fold_selection:
  172.         case block_selection:
  173.         case reg_selection:
  174.         case nodrawn_selection:      return(-1);
  175.       }
  176.  
  177.   return(1);
  178. }
  179. /*}}}  */
  180. /*{{{  invalid_prompt_key*/
  181. public boolean invalid_prompt_key(TOKEN const c)
  182. {
  183.   if (c>=O_NOP && c<K_QUOTE && !(key_info[c-O_NOP]&KTI_P))
  184.    /*{{{  maybe get unhandled OCL-args*/
  185.    { switch (GET_T(c))
  186.       { case COM_II:
  187.            get_arg("skip II");
  188.         case COM_I:
  189.         case COM_C:
  190.         case COM_A:
  191.            get_arg("skip ICA");
  192.         case COM:
  193.            break;
  194.         case COM_IIP:
  195.            get_arg("skip IIP");
  196.         case COM_IP:
  197.            get_arg("skip IP");
  198.         case COM_P:
  199.            for (;;)
  200.             { switch (get_arg("skip P"))
  201.                { case M_END_MACRO:
  202.                     break;
  203.                  case M_INT_STRING:
  204.                     get_arg("skip counter");
  205.                  default:
  206.                     continue;
  207.                }
  208.               break;
  209.             }
  210.            break;
  211.       }
  212.      return(True);
  213.    }
  214.    /*}}}  */
  215.   if (executing_macro && c==O_FLUSH)
  216.      get_arg("skip unused flush arg");
  217.  
  218.   return(False);
  219. }
  220. /*}}}  */
  221. #ifdef MOUSY
  222.   /*{{{  get clickposition and return correct token*/
  223.   /*{{{  MOUSE_UP*/
  224. #  ifdef XTERM
  225. #    define TEST_XTERM(but) (use_mouse==xterm && XTERM_MOUSE_UP(but))
  226. #  else
  227. #    define TEST_XTERM(but) 0
  228. #  endif
  229. #  ifdef MGR
  230. #    define TEST_MGR(but) (use_mouse==mgr && MGR_MOUSE_UP(but))
  231. #  else
  232. #    define TEST_MGR(but) 0
  233. #  endif
  234. #  ifdef OS_MOUSE_TAG
  235. #    define TEST_OS_MOUSE_TAG(but) (use_mouse==OS_MOUSE_TAG && OS_MOUSE_TAG_MOUSE_UP(but))
  236. #  else
  237. #    define TEST_OS_MOUSE_TAG(but) 0
  238. #  endif
  239. #  define MOUSE_UP(b) (TEST_XTERM(b)||TEST_MGR(b)||TEST_OS_MOUSE_TAG(b))
  240.   /*}}}  */
  241.  
  242.   TOKEN handle_click(int const x,int const y, int const but)
  243.   { TOKEN menu_char;
  244.  
  245.     if (bd.f.current==(element*)0)
  246.        return(O_NOP);
  247.     /*{{{  set mouse-vars*/
  248.     decode_buffer_mouse(x,y,True);
  249.     /*{{{  maybe set menu character*/
  250.     if (menu_string)
  251.      { menu_char=O_NOP;
  252.        if (MOUSE_UP(but) && y==screen.h-root_dont_use.h)
  253.         { unsigned char const *s;
  254.           int i;
  255.           int no;
  256.  
  257.           for (i=x,s=menu_string,no=menu_current;i>0;i--)
  258.            { unsigned char c;
  259.  
  260.              switch((c= *s))
  261.               { case ' ':
  262.                    if (no==-1)
  263.                     { no--;
  264.                       i--;
  265.                     }
  266.                    s++;
  267.                 case '\0':
  268.                    menu_char=O_NOP;
  269.                    break;
  270.                 case SPACE_CHAR:
  271.                    i-=sizeof(SPACE)-2;
  272.                    c=' ';
  273.                 default:
  274.                    s++;
  275.                    if (menu_char==O_NOP)
  276.                     { no--;
  277.                       menu_char=c;
  278.                     }
  279.               }
  280.            }
  281.  
  282.         }
  283.      }
  284.     /*}}}  */
  285.     ocl_var[var_m_but].v=but;
  286.     /*}}}  */
  287.     /*{{{  reset keytab search -> started keysequences are cut*/
  288.     find_current=top_list+curr_kbd;
  289.     /*}}}  */
  290.     if (menu_string)
  291.      /*{{{  return code for clicked menu entry, or O_NOP*/
  292.        return(menu_char);
  293.      /*}}}  */
  294.     else
  295.      /*{{{  return the mapped token, if correct value, else O_PROMPT*/
  296.      { TOKEN c=O_PROMPT;
  297.  
  298.        if ((but>=0)&&(but<mouse_number)) c=mouse_mapping[but];
  299.        return(c==O_NOP?O_PROMPT:c);
  300.      }
  301.      /*}}}  */
  302.   }
  303.   /*}}}  */
  304. #endif
  305.